﻿function Get-TSMStoragePool {    
    <#
        .SYNOPSIS
            Get TSM storage pools
                    
        .DESCRIPTION
            The Get-TSMStoragePool returns storage pools belonging to the TSM server

        .PARAMETER StoragePool
            The storage pool to search

        .PARAMETER Type
            The type to search

        .EXAMPLE
            Get-TSMStoragePool

        .NOTES
            Contributors:  David Seibel
            Last Revision Date: 06/04/2015

    #>
    [CmdletBinding()]
    Param(
        [Parameter(Position = 0)]
        $StoragePool,
        
        [Parameter(Position = 1)]
        [ValidateSet("PRIMARY","COPY","ACTIVEDATA")]
        $Type
    )
    
    $whereProps = @()
    $whereProps += [PSCustomObject]@{ "Column" = "STGPOOL_NAME"; "Operator" = "LIKE"; "Value" = $StoragePool }
    $whereProps += [PSCustomObject]@{ "Column" = "POOLTYPE";     "Operator" = "LIKE"; "Value" = $Type }

    $query = Format-TSMQuery -Table "STGPOOLS" -Where $whereProps -OrderBy "STGPOOL_NAME"
    $result = Invoke-TSMCommand -Command $query
    
    $defaultDisplaySet = 'StoragePoolName','StoragePoolType','DeviceClass'
    $typeDefinitions = @{
                        "CHG_TIME"              = [DateTime]
                        "COPYCONTINUE"          = [bool]
                        "CRCDATA"               = [bool]
                        "DEDUPLICATE"           = [bool]
                        "EST_CAPACITY_MB"       = [Double]
                        "HAS_CLIENT_DEDUP_DATA" = [bool]
                        "HIGHMIG"               = [Int32]
                        "LOWMIG"                = [Int32]
                        "MAXSCRATCH"            = [Int32]
                        "MIGCONTINUE"           = [bool]
                        "MIGDELAY"              = [Int32]
                        "MIGPROCESS"            = [Int32]
                        "NUMSCRATCHUSED"        = [Int32]
                        "PCT_LOGICAL"           = [Double]
                        "PCT_MIGR"              = [Double]
                        "PCT_UTILIZED"          = [Double]
                        "RECLAIM"               = [Int32]
                        "REUSEDELAY"            = [Int32]
                        "TRIGGER_PCT_UTIL"      = [Double]
                        }

    $friendlyNames = @{
                        "ACCESS"                = "Access"
                        "ACTIVEDATASTGPOOLS"    = "ActiveDataPools"
                        "AUTOCOPY"              = "AutoCopyMode"
                        "CACHE"                 = "CacheMigratedFiles"
                        "CHG_ADMIN"             = "LastUpdateBy"
                        "CHG_TIME"              = "LastUpdate"
                        "COLLOCATE"             = "Collocate"
                        "COPYCONTINUE"          = "ContinueOnCopyError"
                        "COPYSTGPOOLS"          = "CopyStoragePools"
                        "CRCDATA"               = "CRCData"
                        "DATAFORMAT"            = "StoragePoolDataFormat"
                        "DEDUPLICATE"           = "Deduplicate"
                        "DESCRIPTION"           = "Description"
                        "DEVCLASS"              = "DeviceClass"
                        "EST_CAPACITY_MB"       = "EstimatedCapacityMB"
                        "HAS_CLIENT_DEDUP_DATA" = "HasClientDedupData"
                        "HIGHMIG"               = "HighMigrationPercent"
                        "IDENTIFYPROCESS"       = "ProcessesForIdentifyingDuplicates"
                        "LOWMIG"                = "LowMigrationPercent"
                        "MAXSCRATCH"            = "MaximumScratchVolumes"
                        "MAXSIZE"               = "MaximumSize"
                        "MIGCONTINUE"           = "MigrationContinue"
                        "MIGDELAY"              = "MigrationDelay"
                        "MIGPROCESS"            = "MigrationProcesses"
                        "MIGR_MB"               = "AmountMigratedMB"
                        "MIGR_RUNNING"          = "MigrationInProgress"
                        "MIGR_SECONDS"          = "ElapsedMigrationSeconds"
                        "NEXTSTGPOOL"           = "NextStoragePool"
                        "NUMSCRATCHUSED"        = "NumberScratchVolumesUsed"
                        "OFFSITERCLMLIMIT"      = "OffsiteReclamationLimit"
                        "OVFLOCATION"           = "OverflowLocation"
                        "PCT_LOGICAL"           = "PercentLogical"
                        "PCT_MIGR"              = "PercentMigrated"
                        "PCT_UTILIZED"          = "PercentUtilized"
                        "POOLTYPE"              = "StoragePoolType"
                        "RECLAIM"               = "ReclamationThreshold"
                        "RECLAIMPROCESS"        = "ReclamationProcesses"
                        "RECLAIMSTGPOOL"        = "ReclaimStoragePool"
                        "RECLAMATIONTYPE"       = "ReclamationType"
                        "RECL_RUNNING"          = "ReclamationRunning"
                        "REUSEDELAY"            = "DelayPeriodForVolumeReuse"
                        "SHRED_COUNT"           = "ShredCount"
                        "SPACE_SAVED_MB"        = "SpaceSavedMB"
                        "STGPOOL_NAME"          = "StoragePoolName"
                        "TRIGGER_PCT_UTIL"      = "SpaceTriggerUtilized"
                      }

    return Format-TSMData -Data $result -TypeDefinitions $typeDefinitions -DefaultDisplaySet $defaultDisplaySet -FriendlyNames $friendlyNames
}